package com.gaofei.storage.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gaofei.storage.domain.StorageTbl;
import com.gaofei.storage.service.IStorageTblService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaofei
 * @since 2021-05-29
 */
@RestController
@RequestMapping("/storageTbl")
public class StorageTblController {

    @Autowired
    IStorageTblService storageTblService;
    @RequestMapping("deduct")
    public Boolean deduct(@RequestParam("commodityCode") String commodityCode, @RequestParam("count") Integer count) {
        QueryWrapper<StorageTbl> w = new QueryWrapper<>();
        w.eq("commodity_code",commodityCode);
        StorageTbl one = storageTblService.getOne(w);
        if(one.getCount()>=count){
            one.setCount(one.getCount() - count);
            storageTblService.updateById(one);
            return true;
        }
        return false;
    }
}

